//
//  MKMeHeaderCell.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/10.
//  Copyright © 2017年 cc.moko. All rights reserved.
//

import UIKit

class MKMeHeaderCell: MKBaseTableViewCell {

    var backImage:UIImageView!
    var head:UIImageView!
    var nickName:UILabel!
    var identity:UILabel!
    var number:UILabel!
    
    var userInfoModel:MKUserInfoModel?{
        didSet{
            if let header = userInfoModel?.logourl!{
                self.head.setImage(urlStr: header, placeholderStr: "newMe_defaultHeader")
            }
            if let nickName = userInfoModel?.nickname!{
                self.nickName.text = nickName
            }
            if let numberInt = self.userInfoModel?.userid!{
                self.number.text = "美空号:"+String(numberInt)
            }
            if let usertype = userInfoModel?.usertype!{
                switch usertype {
                case .Actor:
                    self.identity.text = "身份:艺人"
                break
                case .Businessmen:
                    self.identity.text = "身份:商家"
                break
                case .Photographer:
                    self.identity.text = "身份:摄影师"
                break
                case .ActorManager:
                    self.identity.text = "身份:经纪机构"
                break
                }
            }
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.makeUI()
    }
    func makeUI() -> Void {
        self.backImage = UIImageView.init()
        self.backImage.image = UIImage.init(named: "newMe_personInfo_bg")
        self.contentView.addSubview(self.backImage)

        self.head = UIImageView.init()
        self.head.image = UIImage.init(named: "newMe_defaultHeader")
        self.head.layer.borderWidth = 2
        self.head.layer.borderColor = UIColorFromRGB(rgbValue: 0xe3a1f5, A: 1).cgColor
        self.head.clipsToBounds = true
        self.contentView.addSubview(self.head)
        
        self.nickName = UILabel.label(fontSize: 16, textColor: UIColor.white)
        self.contentView.addSubview(self.nickName)
    
        self.identity = UILabel.label(fontSize: 12.5, textColor: UIColor.white)
        self.identity.text = "身份:"
        self.contentView.addSubview(self.identity)
        
        self.number = UILabel.label(fontSize: 12.5, textColor: UIColor.white)
        self.number.text = "美空号:"
        self.contentView.addSubview(self.number)
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.backImage.frame = self.contentView.bounds
        self.head.frame = CGRect.init(x: 40, y: (self.contentView.height - 70) * 0.5, width: 70, height: 70)
        self.nickName.sizeToFit()
        self.identity.sizeToFit()
        self.number.sizeToFit()

        let maxWidth = self.contentView.width - 10 - self.head.right - 20
        self.nickName.frame = CGRect.init(x: self.head.right + 20, y: self.head.top + 10, width: maxWidth, height: self.nickName.height)
        self.identity.frame = CGRect.init(x: self.head.right + 20, y: self.nickName.bottom + 5, width: maxWidth, height: self.nickName.height)
        self.number.frame = CGRect.init(x: self.head.right + 20, y: self.identity.bottom + 5, width: maxWidth, height: self.nickName.height)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
